# 账户上下文
class BsContext:
    def __init__(self, code: str, name: str):
        self.code = code
        self.name = name
        self.hand = 0  # 持有手数
        self.capital_all = 200000  # 总资金
        self.capital_available = 200000  # 可用资金
        self.capital_occupy = 0  # 占用资金
        self.position = 0  # 仓位(0-100)
        self.deal_info = []  # 交易记录


# ratio 要增加到的仓位(0-100)
# price 交易价格
# date  交易日期
def buy(context: BsContext, ratio: int, price, date):
    b_or_s(context, ratio, price, date, 1)


# 要减到的仓位(0-100)
# price 交易价格
# date  交易日期
def sell(context: BsContext, ratio: int, price, date):
    b_or_s(context, ratio, price, date, -1)


# 要调到的仓位(0-100)
# price 交易价格
# date  交易日期
# flag : 1买入 -1 卖出
def b_or_s(context: BsContext, ratio: int, price, date, flag):
    if (context.position - ratio) * flag >= 0:
        return
    deal_hand = 0
    if flag == 1:
        deal_hand = int(
            (context.capital_available * (ratio - context.position)) / ((100 - context.position) * price * 100))
    elif flag == -1:
        deal_hand = min(int((context.hand * (context.position - ratio)) / context.position), context.hand)
    if deal_hand <= 0:
        return
    context.hand = context.hand + deal_hand * flag
    context.capital_occupy = int(context.hand * price * 100)
    context.capital_available = int(context.capital_available - deal_hand * price * 100 * flag)
    context.capital_all = int(context.capital_occupy + context.capital_available)
    context.position = round(context.capital_occupy / context.capital_all * 100)
    context.deal_info.append({'code': context.code, 'name': context.name, 'date': date, 'bs': flag, 'price': price,
                              'capital': context.capital_all})


if __name__ == '__main__':
    print(int(25 / 6))
